//-----------------------------------------------------------------------
// <copyright file="a_UserAccessCategoryDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_UserAccessCategoryDAOBase
    {
        #region Common methods
        public virtual a_UserAccessCategory Createa_UserAccessCategoryFromReader(IDataReader reader)
        {
            a_UserAccessCategory item = new a_UserAccessCategory();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("AID"))) item.AID = (int)reader["AID"];
                if (!reader.IsDBNull(reader.GetOrdinal("UserID"))) item.UserID = (int)reader["UserID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatID"))) item.CatID = (int)reader["CatID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CatLevel"))) item.CatLevel = (byte)reader["CatLevel"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_UserAccessCategory methods
            
        public virtual void Createa_UserAccessCategory(a_UserAccessCategory a_UserAccessCategory)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserAccessCategory_ins");
                
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, a_UserAccessCategory.UserID);
                database.AddInParameter(dbCommand, "@CatID", DbType.Int32, a_UserAccessCategory.CatID);
                database.AddInParameter(dbCommand, "@CatLevel", DbType.Byte, a_UserAccessCategory.CatLevel);
                database.AddOutParameter(dbCommand, "@AID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_UserAccessCategory.AID = (int)database.GetParameterValue(dbCommand, "@AID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_UserAccessCategory methods
        
        public virtual void Updatea_UserAccessCategory(a_UserAccessCategory a_UserAccessCategory)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserAccessCategory_upd");            
                
                database.AddInParameter(dbCommand, "@AID", DbType.Int32, a_UserAccessCategory.AID);
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, a_UserAccessCategory.UserID);
                database.AddInParameter(dbCommand, "@CatID", DbType.Int32, a_UserAccessCategory.CatID);
                database.AddInParameter(dbCommand, "@CatLevel", DbType.Byte, a_UserAccessCategory.CatLevel);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_UserAccessCategory methods
        public virtual void Deletea_UserAccessCategory(int aid)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserAccessCategory_del");
                
                database.AddInParameter(dbCommand, "@AID", DbType.Int32, aid);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_UserAccessCategory methods
        
        public virtual a_UserAccessCategory Geta_UserAccessCategory(int aid)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserAccessCategory_sel");
                
                database.AddInParameter(dbCommand, "@AID", DbType.Int32, aid);
                
                a_UserAccessCategory a_UserAccessCategory =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_UserAccessCategory = Createa_UserAccessCategoryFromReader(reader);
                        reader.Close();
                    }
                }
                return a_UserAccessCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_UserAccessCategoryList methods
        public virtual a_UserAccessCategoryCollection Geta_UserAccessCategoryList(a_UserAccessCategoryColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserAccessCategory_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_UserAccessCategoryCollection a_UserAccessCategoryCollection = new a_UserAccessCategoryCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_UserAccessCategory a_UserAccessCategory = Createa_UserAccessCategoryFromReader(reader);
                        a_UserAccessCategoryCollection.Add(a_UserAccessCategory);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_UserAccessCategoryCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_UserAccessCategoryCollection Geta_UserAccessCategoryList(a_UserAccessCategoryColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_UserAccessCategoryList(orderBy, orderDirection, 0, 0, out totalRecords);
        }

        public virtual a_UserAccessCategoryCollection Geta_UserAccessCategoryList_uid(int uid, a_UserAccessCategoryColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserAccessCategory_selList_uid");
                database.AddInParameter(dbCommand, "@uid", DbType.Int32, uid);
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);

                a_UserAccessCategoryCollection a_UserAccessCategoryCollection = new a_UserAccessCategoryCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_UserAccessCategory a_UserAccessCategory = Createa_UserAccessCategoryFromReader(reader);
                        a_UserAccessCategoryCollection.Add(a_UserAccessCategory);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_UserAccessCategoryCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public virtual a_UserAccessCategoryCollection Geta_UserAccessCategoryList_uid(int uid, a_UserAccessCategoryColumns orderBy, OrderDirection orderDirection)
        {
            int totalRecords = 0;
            return Geta_UserAccessCategoryList_uid(uid, orderBy, orderDirection, 0, 0, out totalRecords);
        }

        public virtual a_UserAccessCategoryCollection Geta_UserAccessCategoryList_cid(int cid, a_UserAccessCategoryColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserAccessCategory_selList_cid");
                database.AddInParameter(dbCommand, "@cid", DbType.Int32, cid);
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);

                a_UserAccessCategoryCollection a_UserAccessCategoryCollection = new a_UserAccessCategoryCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_UserAccessCategory a_UserAccessCategory = Createa_UserAccessCategoryFromReader(reader);
                        a_UserAccessCategoryCollection.Add(a_UserAccessCategory);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_UserAccessCategoryCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public virtual a_UserAccessCategoryCollection Geta_UserAccessCategoryList_cid(int cid, a_UserAccessCategoryColumns orderBy, OrderDirection orderDirection)
        {
            int totalRecords = 0;
            return Geta_UserAccessCategoryList_cid(cid, orderBy, orderDirection, 0, 0, out totalRecords);
        }

        public virtual a_UserAccessCategoryCollection Geta_UserAccessCategoryList_cid_uid(int uid, int cid, a_UserAccessCategoryColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_UserAccessCategory_selList_cid_uid");
                database.AddInParameter(dbCommand, "@cid", DbType.Int32, cid);
                database.AddInParameter(dbCommand, "@uid", DbType.Int32, uid);
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);

                a_UserAccessCategoryCollection a_UserAccessCategoryCollection = new a_UserAccessCategoryCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_UserAccessCategory a_UserAccessCategory = Createa_UserAccessCategoryFromReader(reader);
                        a_UserAccessCategoryCollection.Add(a_UserAccessCategory);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_UserAccessCategoryCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public virtual a_UserAccessCategoryCollection Geta_UserAccessCategoryList_cid_uid(int uid, int cid, a_UserAccessCategoryColumns orderBy, OrderDirection orderDirection)
        {
            int totalRecords = 0;
            return Geta_UserAccessCategoryList_cid_uid(uid, cid, orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}